// pages/user/chil-coms/collection-bar/CollectionBar.js
import { z_getSetting, z_openSetting, z_chooseAddress } from '../../../../utils/async_wx'
import regeneratorRuntime from '../../../../lib/runtime/runtime'
const App = getApp()

Component({

  options: {
    addGlobalClass: true
  },
  pageLifetimes: {
    show: function() {
      // 页面被展示
      this.data.count.收藏商品 = App.globalData.collectionCount
      this.setData({count:{...this.data.count}})
    }
  },
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    count:{
      收藏店铺:0,
      收藏商品:0,
      关注商品:0,
      我的足迹:0
    },
    collectionData:[
      '收藏店铺',
      '收藏商品',
      '关注商品',
      '我的足迹'
    ],
    order:[
      '全部订单',
      '待付款',
      '待收货',
      '退款/退货',
    ],
    orderIcon:{
      '全部订单':'icon-dingdan',
      '待付款':'icon-daifukuan01',
      '待收货':'icon-daishouhuo',
      '退款/退货':'icon-tuikuan'
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //handleClick
    handleClickCollect(event) {
      const { index } = event.currentTarget.dataset
      if(index === 1){
        wx.navigateTo({url: '/pages/collect/collect'});
        return
      }
      wx.showToast({
        title: '功能实现中~',
        icon: 'none',
        duration: 1500,
        mask: true,
      });

    },
    // handleClickOrder
    handleClickOrder(){
      wx.showToast({
        title: '功能实现中~',
        icon: 'none',
        duration: 1500,
        mask: true,
      });
    },

    // managementAddress
    async managementAddress(){
      try{
        //1.获取用户的授权情况
      const result1 = await z_getSetting()
      const scopeAddress = result1.authSetting['scope.address']
      if(scopeAddress === false){
        //3.诱导用户打开设置授权jiemian
        const result3 = await z_openSetting()
        if(result3.authSetting['scope.address']){
          const address = await z_chooseAddress()
          wx.setStorageSync('address', address)
        }
        return     
      }
      //2.如果为true或者undefind,调用获取地址
      const address = await z_chooseAddress()
      wx.setStorageSync('address', address)
      }catch(error){
        console.log(error)
      }
    },

    //contactOur
    contactOur(){
      // console.log('客服绘画')
    },

    //suggesion
    suggesion(){
      wx.navigateTo({url: '/pages/feedback/feedback'});
    }

  }
})
